#!/bin/sh

dockerpids=$(docker ps -f name="quarkus-jdbc-mcp-jvm" | awk '{print $1}' | grep -v CONTAINER)
for dockerpid in $dockerpids
do
  echo "被删除的容器 $dockerpid"
  docker stop $dockerpid
  docker rm $dockerpid
done
echo "容器已删除完毕！"

ipids=$(docker images | grep "none*" | awk '{print $3}')
for imagesid in $ipids
do
  echo "被删除的空镜像 $imagesid"
  docker rmi $imagesid
done

ipids=$(docker images | grep "quarkus/jdbc-mcp-jvm" | awk '{print $3}')
for imagesid in $ipids
do
  echo "被删除的镜像 $imagesid"
  docker rmi $imagesid
done
# shellcheck disable=SC2155
export SERVER_IP=$(hostname -I | awk '{print $1}')

cd ./build
docker build -f Dockerfile.jvm -t quarkus/jdbc-mcp-jvm .
echo "镜像安装完成"
cd ../
docker-compose -f docker-compose.yaml up -d
echo "容器启动完成,结束..."